/*
 * Copyright (C) 2014 Will Dignazio
 */
#include <util.h>
#include <mstore.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>

typedef struct MKey MKey;
typedef struct MNode MNode;

extern int	keycmp(MKey *k1, MKey *k2);
extern MNode*	mstore_search_node(MNode *mn, MHash mid, void **data, Error *err);
extern MNode*	allocnod(Error *err);
extern MKey*	allockey(void *data, u64 len, Error *err);

struct MKey
{
	MNode*	node;		// Contianing Node
	MKey*	next;		// Next key in Node
	MKey*	prev;		// Preivous key in Node
	MNode*	lcn;		// Left child node
	MNode*	rcn;		// Right child node

	MHash	mid;		// Key ID
	void*	data;		// Data pointer
};

struct MNode
{
	MNode*		parent;	// Parent Node
	MKey*		khead;	// Head key
	u64	keys;	// Key count
};

struct MStore
{
	MNode*	nhead;	// Head Node
	u64	min;	// Minimum child nodes per node
			// Max is min * 2
};
